package com.cnc.utils;

import com.cnc.pojo.User;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

public class JsonUtil {
    private static ObjectMapper mapper=new ObjectMapper();

    public static String objectToJson(Object obj) {
        String json = null;
        try {
            json = mapper.writeValueAsString(obj);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return json;
    }

    public static Object JsonToObject(String str,Class c) {
        Object obj = null;
        try {
            obj = mapper.readValue(str, c);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return obj;
    }
}
